<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
	<link id="easyuiTheme" rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/icon.css"/>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
	    var contextPath = function() {
	        return  "/" + location.pathname.split("/")[1];
	    }
	    
		function getValue(name){
			var str=window.location.search;
			if (str.indexOf(name)!=-1){
				var pos_start=str.indexOf(name)+name.length+1;
				var pos_end=str.indexOf("&",pos_start);
				if (pos_end==-1){
					return str.substring(pos_start);
				} else {
					return str.substring(pos_start,pos_end);
				}
			} else {
				return "";
			}
		}
		
		var  themeName = getValue("theme");
		if (themeName!=""){
		    var cssurl  = $('#easyuiTheme').attr('href');  
		    var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';  
		    $('#easyuiTheme').attr('href', href);  
		}   
		
	    //将表单数据转为json
	    function form2Json(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	        }
	        jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        jsonStr += '}';
	        var json = JSON.parse(jsonStr);
	        return json;
	    }
	    
	    //将表单数据转为json格式的字符串，当然也可以JSON.stringify(data)
	    function form2JsonStr(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
	        }
	        jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        jsonStr += '}';
	        return jsonStr;
	    }
	</script>

</head>

<style>
    .datagrid-btable{
        width:100%;
    }
    .datagrid-header-inner{
        width:100%;
    }
    .datagrid-header{
        width:100%;
    }
    .datagrid-htable{
        width:100%;
    }
    .datagrid-cell{margin:auto;}
    .fitem{text-align:center}
    .ftitle{text-align:center}
</style>

<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:''">	  
        <table id="datagrid"  class="easyui-datagrid" style="width:100%;height:100%"></table>
        <div id="dgtoolbar">		
        	<form name="searchform" method="post" action="" id ="searchform">
				<td width="70" height="30">
					<strong>&nbsp;投保单号：</strong>
				    <input class="easyui-textbox" type="text" id="search_insureNo" name="insureNo" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;&nbsp;投&nbsp;保&nbsp;人：</strong>
				    <input class="easyui-textbox" type="text" id="search_application" name="application" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;手机号码：</strong>
				    <input class="easyui-textbox" type="text" id="search_mobilephone" name="mobilephone" size=20 >
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;保单状态：</strong>
				    <select class="easyui-combobox" id="search_status" name="status" editable="false">
				    	<option value="0" selected="selected">全部</option>
				    	<option value="1001">未接收</option>
				    	<option value="1002">已接收</option>
				    	<option value="1003">寄送中</option>
				    	<option value="1004">已寄回回执</option>
				    	<option value="1005">已退回</option>
				    	<option value="1006">已回销</option>
				    	<option value="1007">已撤件</option>
				    	<option value="1008">已退保</option>
						<option value="1009">已强撤</option>
						<option value="1010">单程已签收</option>
				    </select>	    			
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;保单类型：</strong>
				    <select id="search_policy_type" class="easyui-combobox" name="policy_type" editable="false">
				    	<option value="" selected="selected">全部</option>
				    	<option value="纸质保单">纸质保单</option>
				    	<option value="电子保单">电子保单</option>
				    </select>	    			
				</td>	
				<br>
				<td width="70" height="30">
					<strong>&nbsp;销售单位：</strong>
				    <input class="easyui-textbox" type="text" id="search_project" name="project" size=20 >
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;寄送次数：</strong>
				    <input class="easyui-textbox" type="text" id="search_deliverCount1" name="deliverCount1" size=6 >
				    <strong>-</strong>					
				    <input class="easyui-textbox" type="text" id="search_deliverCount2" name="deliverCount2" size=7 >
				</td>	
				<td width="70" height="30">
					<strong>&nbsp;&nbsp;寄送地址：</strong>
				    <input class="easyui-textbox" type="text" id="search_address" name="address" size=43 >
				</td>		
				<br>
				<td width="70" height="30">
					<strong>&nbsp;接件日期：</strong>
					<input id="search_intro_time1" name="introTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_intro_time2" name="introTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>
				<td width="70" height="30">
					<strong>&nbsp;投保日期：</strong>
					<input id="search_insure_time1" name="insureTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_insure_time2" name="insureTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;回销日期：</strong>
					<input id="search_receipt_time1" name="receiptTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_receipt_time2" name="receiptTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;退回日期：</strong>
					<input id="search_return_time1" name="returnTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_return_time2" name="returnTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>				
				</td>
			</form>
			<a id="submit_search">搜索</a>
			<a id="reset_search">重置</a>
            <a id="btn_add" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" >新增</a>
            <a id="btn_edit" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >修改</a>
            <a id="btn_delete" href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" >删除</a>
        </div>
    </div>
</div>

<div id="dialog_addmodifypolicy" class="easyui-dialog" 
	modal="true" closed="true" 
	style="width:670px;height:490px;padding:10px 20px"
	buttons="#buttons_addmodifypolicy">
    <form id="form_addmodifypolicy" method="post" >
        <div class="fitem">
            <label>投保单号：</label>
            <input id="id_insure_no" type="text" name="insure_no"  readonly="readonly" class="easyui-textbox" required="true" style="align:left;width:120px"/>
        	&nbsp;&nbsp;&nbsp;&nbsp;
            <label>投 保 人：</label>
            <input type="text" name="applicant" class="easyui-textbox" required="true"  style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;            
			<label>保单状态：</label>
		    <select name="status" class="easyui-combobox" style="width:120px" editable="false">
		    	<option value="1001">未接收</option>
		    	<option value="1002">已接收</option>
		    	<option value="1003">寄送中</option>
		    	<option value="1004">已寄回回执</option>
		    	<option value="1005">已退回</option>
		    	<option value="1006">已回销</option>
		    	<option value="1007">已撤件</option>
		    	<option value="1008">已退保</option>
				<option value="1009">已强撤</option>
				<option value="1010">单程已签收</option>
		    </select>	    			
        </div>
        <br>
        <div class="fitem">
            <label>所属区域：</label>
            <input type="text" name="area" class="easyui-textbox" style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>移动电话：</label>
            <input type="text" name="mobilephone" class="easyui-textbox" required="true" style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>固定电话：</label>
            <input type="text" name="telephone" class="easyui-textbox" style="width:120px"/>
        </div>
        <br>
        <div class="fitem">
            <label>联系地址：</label>
            <input type="text" name="address" class="easyui-textbox" style="width:540px"/>
        </div>
        <br>
        <div class="fitem">
            <label>险种内容：</label>
            <input type="text" name="product" class="easyui-textbox" style="width:330px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>线上保费：</label>
            <input type="text" name="premium" class="easyui-textbox" style="width:100px"/>
            <label>元</label>
        </div>
        <br>
        <div class="fitem">
        	<label>所属项目：</label>
            <input type="text" name="project" class="easyui-textbox" required="true" style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>TSR小组：</label>
            <input type="text" name="tsr_name" class="easyui-textbox" style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>TSR姓名：</label>
            <input type="text" name="tsr_group" class="easyui-textbox" style="width:120px"/>
        </div>
        <br>
        <div class="fitem">
            <label>投保日期：</label>
			<input name="insure_time" class="easyui-datebox" required="true" editable="fasle" style="width:120px"></input>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>到达日期：</label>
			<input name="intro_time" class="easyui-datebox" required="true" editable="fasle" style="width:120px"></input>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>回销时间：</label>
			<input name="receipt_time" class="easyui-datetimebox" editable="fasle" style="width:120px"></input>
        </div>
        <br>
        <div class="fitem">
            <label>退回日期：</label>
			<input name="return_time" class="easyui-datebox" editable="fasle" style="width:120px"></input>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>撤件日期：</label>
			<input name="cancel_time" class="easyui-datebox" editable="fasle" style="width:120px"></input>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>退保日期：</label>
			<input name="surrender_time" class="easyui-datebox" editable="fasle" style="width:120px"></input>
        </div>
        <br>
        <div class="fitem">
            <label>寄送次数：</label>
            <input type="text" name="deliver_count" class="easyui-textbox" style="width:120px"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>保单类型：</label>
		    <select name="policy_type" class="easyui-combobox" style="width:120px" editable="false">
		    	<option value=""></option>
		    	<option value="纸质保单">纸质保单</option>
		    	<option value="电子保单">电子保单</option>
		    </select>	    	
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <br>
        <div class="fitem">
            <label>备注说明：</label>
            <input type="text" name="remark" class="easyui-textbox" data-options="multiline:true" style="width:540px;height:60px"/>
        </div>
    </form>
    <div id="buttons_addmodifypolicy">
        <a id="btn_addmodifypolicy" href="#" class="easyui-linkbutton">保存</a>
		<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dialog_addmodifypolicy').dialog('close')">取消</a>
	</div>
</div>
</body>

<script type="text/javascript">

    $(function () {
    	//touch页面,记录用户进入页面
		$.ajax({
			url : contextPath()+"/mdmis/touch",
			type : "get",
			data : {
				//"traceRandom":trace_random,
    			//"recordID":trace_recordID,
    			"target":location.pathname,
    			"operation":"[进入页面]保单详情页"
    		},
			dataType : "json",	// 数据返回类型
            cache : false, 	// 是否缓存
            async : true   	// 默认为true 异步请求
		});
		
    	$('#datagrid').datagrid({
    		loadMsg:'正在加载数据...',
    	    url:contextPath()+'/mdmis/getPolicyListByCondition',
    	    toolbar:'#dgtoolbar',
    	    queryParams: form2Json("searchform"),
    	    pagination: true,
            pageSize:'100',
            pageList:[100,500,900],            
            rownumbers: true,
            striped: true,
            fit: true,
            fitColumns: false, //不自动适应列宽
            singleSelect: false, 
            selectOnCheck: true,
            checkOnSelect: true,
            remoteSort: false,
    	    columns:[[
    			{field:'ck',checkbox:true}, 
    			{field:'insure_no',title:'投保单号',sortable:true,width:130},
    			{field:'project',title:'所属项目',width:60},
    			{field:'policy_type',title:'保单类型',width:60},
    			{field:'intro_time',title:'接件日期',sortable:true,width:80},
    			{field:'insure_time',title:'投保日期',sortable:true,width:80},
    			{field:'status_info',title:'保单状态',align:'center',width:60},
    			{field:'receipt_time',title:'回销日期',sortable:true,width:80},
    			{field:'return_time',title:'退回日期',width:80},
    			{field:'applicant',title:'投保人',align:'center',width:60},
    			{field:'mobilephone',title:'手机',width:100},
    			{field:'area',title:'地区',width:60},
    			{field:'address',title:'地址',width:500},
    			{field:'telephone',title:'电话',width:100},
    			{field:'product',title:'险种名称',width:300},
    			{field:'premium',title:'保费',align:'right',width:60},
    			{field:'tsr_name',title:'TSR姓名',align:'center',width:60},
    			{field:'tsr_group',title:'TSR小组',align:'center',width:60},
    			{field:'cancel_time',title:'撤件日期',width:80},
    			{field:'surrender_time',title:'退保日期',width:80},
    			{field:'deliver_count',title:'配送次数',width:80},
    			{field:'remark',title:'备注',width:600}
    	    ]]
    	});  
    	
    	  
		//点击搜索
		$("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true }).click(function () {
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击重置
		$("#reset_search").linkbutton({ iconCls: 'icon-reload', plain: true }).click(function () {
            $('#search_insureNo').textbox('setValue',''); //将用户名的输入框清空
            $('#search_application').textbox('setValue',''); //将中文名的输入框清空
            $('#search_mobilephone').textbox('setValue',''); //将中文名的输入框清空
            $('#search_project').textbox('setValue',''); 
            $('#search_address').textbox('setValue',''); 
            $('#search_status').combobox('select','0');
            $('#search_policy_type').combobox('select','');
            $('#search_deliverCount1').textbox('setValue',''); 
            $('#search_deliverCount2').textbox('setValue',''); 
            $('#search_intro_time1').textbox('setValue',''); 
            $('#search_intro_time2').textbox('setValue',''); 
            $('#search_insure_time1').textbox('setValue',''); 
            $('#search_insure_time2').textbox('setValue',''); 
            $('#search_receipt_time1').textbox('setValue',''); 
            $('#search_receipt_time2').textbox('setValue',''); 
            $('#search_return_time1').textbox('setValue',''); 
            $('#search_return_time2').textbox('setValue',''); 
            //$('#datagrid').datagrid('reload');  
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击新增
		$("#btn_add").linkbutton({ iconCls: 'icon-add', plain: true }).click(function () {
			//清空表单
			//form('clear')会将所有框都清空，包括combobox。
			//$('#form_addmodifypolicy').form('clear')
			//form('reset')则只会清空日期框，不会清空combobox。
			$('#form_addmodifypolicy').form('reset');
	        $('#dialog_addmodifypolicy').dialog('open').dialog('setTitle','新增保单信息');
			//将投保单输入栏的编辑状态修改为可编辑
            $('#id_insure_no').textbox('readonly',false);
			//将窗口中的保存按钮修改为新增操作
			$("#btn_addmodifypolicy").unbind("click");
			//必须先解除绑定，再重新绑定，否则可能会出现重复响应。						
			$("#btn_addmodifypolicy").bind("click", function() {
				$.messager.confirm('Confirm','确定要添加该保单信息?',function(r){
				    if (r){
				    	$.ajax({
							type:'POST',
							url:contextPath()+'/mdmis/addPolicy',
						    data:form2JsonStr('form_addmodifypolicy'),
						    dataType:'json',
							contentType: 'application/json',
						    beforeSend: function () {
								$.messager.progress({
									title: '提示', 
									msg: '操作进行中，请稍候……', 
									text: '' 
								});
						    },
						    complete: function () {
								$.messager.progress('close');
						    },
						    success:function(result){				
								if (result.success){
					                $('#datagrid').datagrid('reload');	// reload data
			                        $('#dialog_addmodifypolicy').dialog('close');
					                $.messager.show({
					                    title: 'Success',
					                    msg: '操作完成！'
					                });
					            } else {
					                $.messager.show({	// show error message
					                    title: 'Error',
					                    msg: result.errMsg
					                });
					            }
							}
						});
					}
				});						      
	        });
        });
		//点击编辑
		$("#btn_edit").linkbutton({ iconCls: 'icon-edit', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		    	  if (rows.length==0) {
						$.messager.show({
						    title: '操作错误',
						    msg: '您未勾选任何数据，请选择需要编辑的数据！'
						});
		    	  } else if (rows.length>1){
						$.messager.show({
						    title: '操作错误',
						    msg: '您已经勾选了'+rows.length+'条数据，请勿选择多条数据进行同时编辑！'
						});		    		  
		    	  } else {
		    		  	//取出保单信息
		    		  	var policyInfo = rows[0];
						//显示未修改前的信息
						$('#form_addmodifypolicy').form('load',policyInfo);
				        $('#dialog_addmodifypolicy').dialog('open').dialog('setTitle','修改信息');
						//将投保单输入栏的编辑状态修改为不能编辑
           	 			$('#id_insure_no').textbox('readonly',true);
						//将窗口中的保存按钮修改为保存操作
						$("#btn_addmodifypolicy").unbind("click");
						//必须先解除绑定，再重新绑定，否则可能会出现重复响应。						
						$("#btn_addmodifypolicy").bind("click", function() {
							$.messager.confirm('Confirm','确定要更新该保单信息?',function(r){
							    if (r){
							    	$.ajax({
										type:'POST',
										url:contextPath()+'/mdmis/modifyPolicy',
									    data:form2JsonStr('form_addmodifypolicy'),
									    dataType:'json',
										contentType: 'application/json',
									    beforeSend: function () {
											$.messager.progress({
												title: '提示', 
												msg: '操作进行中，请稍候……', 
												text: '' 
											});
									    },
									    complete: function () {
											$.messager.progress('close');
									    },
									    success:function(result){				
											if (result.success){
								                $('#datagrid').datagrid('reload');	// reload data
						                        $('#dialog_addmodifypolicy').dialog('close');
								                $.messager.show({
								                    title: 'Success',
								                    msg: '操作完成！'
								                });
								            } else {
								                $.messager.show({	// show error message
								                    title: 'Error',
								                    msg: result.errMsg
								                });
								            }
										}
									});
								}
							});						      
				        });
		    	  }		    	  
		      }
		});
		$("#btn_delete").linkbutton({ iconCls: 'icon-remove', plain: true }).click(function () {
		      var rows = $('#datagrid').datagrid('getSelections');
		      if (rows){
		          $.messager.confirm('Confirm','确定要删除所选择的数据?',function(r){
		              if (r){
		            	  var ids="";
		            	  for (var i in rows){
		            		  ids += rows[i].insure_no+",";
		            	  }
		                  $.post(contextPath()+'/mdmis/removePolicy',{insureNos:ids},function(result){
		                      if (result.success){
		                          $('#datagrid').datagrid('reload');	// reload data
		                          $.messager.show({
		                              title: 'Success',
		                              msg: '操作完成！'
		                          });
		                      } else {
		                          $.messager.show({	// show error message
		                              title: 'Error',
		                              msg: result.errMsg
		                          });
		                      }
		                  },'json');
		              }
		          });
		      }
        });
    })

</script>


</html>



